import type { User, UseProfile } from '@/types/data'
import type { ProfileAction } from '@/types/store'

type ProfileState = {
	//小写：大写（导入）
	user: User
	userProfile: UseProfile
}

const initialState = {
	user: {},
	userProfile: {},
} as ProfileState

export const profile = (
	state = initialState,
	action: ProfileAction
): ProfileState => {
	switch (action.type) {
		case 'profile/getUser':
			return {
				...state,
				user: action.payload,
			}

		case 'profile/getUseProfile':
			return {
				...state,
				userProfile: action.payload,
			}

		case 'profile/update':
			return {
				...state,
				userProfile: {
					...state.userProfile,
					...action.payload,
				},
			}

		default:
			return state
	}
}
